package com.xframe.common.core.service.login;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Service;

/**
 * 功能描述: 对重复登录的处理策略算法工厂
 *
 * @author xufeng
 * @version 1.0
 * @date 2023-5-31
 */
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
//@Service
@Log4j2
public class RepeatLoginstrategyFactory{

    @Value("${login.RepeatLoginstrategyClassName}")
    private String repeatLoginstrategyClassName;

    private IRepeatLoginstrategy curStrategy = null;

    public IRepeatLoginstrategy getCurStrategy(){
        try {
            if(curStrategy == null || !repeatLoginstrategyClassName.equals(curStrategy.getClass().getName())) {
                Class dataType = Class.forName(repeatLoginstrategyClassName);
                curStrategy = (IRepeatLoginstrategy) dataType.newInstance();
            }
        }catch (Exception e){
            curStrategy =  new DefRepeatLoginstrategy();
        }
        return curStrategy;
    }



}
